package cn.bblocks.common.i18n.demo.controller;


import cn.bblocks.common.i18n.I;
import cn.bblocks.common.i18n.demo.params.ValidParam;
import cn.bblocks.common.i18n.demo.util.R;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>Project: bb-i18n - TestController</p>
 * <p>描述：测试用</p>
 *
 * @Author Zhao [125043150@qq.com]
 * @Date 2024/4/1 17:44
 * @Version 1.0
 * @since 8
 */
@RestController
@RequestMapping("/demo")
public class TestController {

    /**
     * 成功返回-带数据
     * @return
     */
    @GetMapping("/xxx")
    public R xxx1() {
        return R.ok("Hello，World");
    }

    /**
     * 成功返回
     * @param request
     * @return
     */
    @GetMapping("/i18n")
    public R i18n(HttpServletRequest request) {
        return R.ok();
    }

    /**
     * 错误，带错误信息
     * @param param
     * @return
     */
    @GetMapping("/i18n2")
    public R i18n2(String param) {
        String msg = I.n(String.valueOf("must_err"),"param");
        return R.failed(msg);
    }

    /**
     * 参数校验
     * @param param
     * @return
     */
    @PostMapping("/i18nValid")
    public R i18nValid(@RequestBody  @Validated ValidParam param) {
        return R.ok();
    }

    @PostMapping("/i18nValidForm")
    public R i18nValidForm( @Validated ValidParam param) {
        return R.ok();
    }

    /**
     * 异常接口
     * @return
     */
    @GetMapping("/i18nException")
    public R i18nException() {
        if(1==1){
            throw new RuntimeException("test");
        }
        return R.ok();
    }

}
